<template>
	<view class="gift-home">
		<view class="banner" v-if="img">
			<image mode="widthFix" :src="img"></image>
		</view>
		<view class="title">
			<view class="titleLine"></view>
			<view class="titleText">馈赠亲朋好友</view>
			<view class="titleLine"></view>
		</view>
		<view class="cardBox">
			<view class="card" v-for="(item, index) in gift" :key="index" @tap="purchase" :data-id="item.id">
				<image :src="item.img_url"></image>
				<view>{{item.title}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp().globalData;

	export default {
		data() {
			return {
				img: "",
				gift: ""
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		async onLoad(options) {
			await this.$onLaunched;
			// #ifdef MP-ALIPAY
			if (JSON.stringify(options) == '{}') {
				options = my.getLaunchOptionsSync().query;
			}
			// #endif
			if (options && (options.store_id)) {
				this.$store.store_id = options.store_id;
			}

			var that = this;
			getApp().globalData.sendRequest({
				url: '/GiftCard/giftCardList',
				type: "post",
				data: {},
				success: function(res) {
					console.log(res);

					if (res.banner) {
						that.setData({
							img: res.banner
						});
					}

					if (res.status == 1) {
						that.setData({
							gift: res.list
						});
					} else {
						that.setData({
							gift: null
						});
					}
				}
			});
		},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage(res) {
			return {
				title: '礼品卡中心',
				path: '/pages/mine/gift_home/gift_home?store_id=' + this.$store.store_id +
					'&share_uid=' + app.XcxData.userInfo.uid,
				success: function(res) { // 转发成功
				},
				fail: function(res) { // 转发失败
				}
			};
		},
		methods: {
			purchase: function(e) {
				console.log(e);
				var id = e.currentTarget.dataset.id;
				uni.navigateTo({
					url: '../gift_purchase/gift_purchase?id=' + id
				});
			}
		}
	};
</script>
<style>
	@import "./gift_home.css";

	.gift-home {
		width: 100%;
	}
</style>
